package com.qf.kady.ssm.controller;

import com.qf.kady.ssm.pojo.DropLog;
import com.qf.kady.ssm.service.DropLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: kady
 * \* Date: 2021/4/21
 * \* Time: 11:50
 * \* 千峰JAVA2101班
 * \* Description: 借还控制层
 * \
 */
@Controller
@RequestMapping("/admin")
public class DropController {
    @Autowired
    private DropLogService dropLogService;

    @GetMapping("/lendlist.html")
    public ModelAndView toAdminLenList(){
        List<DropLog> dropLogList = dropLogService.getDropLogList();
        ModelAndView mav = new ModelAndView();
        mav.addObject("list",dropLogList);
        mav.setViewName("/admin/admin_lend_list");
        return mav;
    }

    @RequestMapping("/deletelend.html")
    public ModelAndView deleteLog(Long serNum, Model model){
        boolean res = dropLogService.deleteDropLog(serNum);
        if(res){
            model.addAttribute("succ","删除成功");
        }else{
            model.addAttribute("error","删除失败");
        }
        return toAdminLenList();
    }

}
